package org.tigris.gef.presentation;

import java.awt.*;

/**
 * Created by xiaobyu on 7/19/2016.
 *
 */
public class FigAnchorNode extends FigNode{

    public static final int SIZE = 16;

    private Fig portFig;

    public FigAnchorNode(Object owner, int x, int y) {
        portFig = new FigLocator(x - SIZE / 2, y - SIZE / 2);
        addFig(portFig);

        setBounds(portFig.getBounds());
        setOwner(owner);
    }

    public void setOwner(Object owner) {
        bindPort(owner, portFig);
        super.setOwner(owner);
    }

    public void setBoundsImpl(int x, int y, int w, int h) {
        portFig.setBounds(x, y, SIZE, SIZE);
        super.setBoundsImpl(x, y, SIZE, SIZE);
    }

    public Dimension getMinimumSize() {
        return new Dimension(SIZE, SIZE);
    }

    public void removeFigEdge(FigEdge fe) {
        super.removeFigEdge(fe);
        deleteFromModel();
    }

    private class FigLocator extends FigRect {

        public FigLocator(int x, int y) {
            super(x, y, SIZE, SIZE);
            setVisible(true);
            setFilled(false);
            setLineWidth(0);
        }

        public Point getClosestPoint(Point anotherPt) {
            return new Point(_x + _w / 2, _y + _h/2);
        }

        public void setLineWidth(int width) {
            super.setLineWidth(0);
        }

        public void setVisible(boolean visible) {
            super.setVisible(true);
        }

        public void setFilled(boolean filled) {
            super.setFilled(false);
        }
    }
}
